using System;
using UnityEngine;
using UnityEngine.UI;
public class EnemyAnger : MonoBehaviour
{
    public Tracer tracer;
    public float curEnemyAnger = 0;
    public float maxEnemyAnger = 100f;
    public float increaseSpeed = 10f;
    public float decreaseSpeed = 5f;
    public float GameOverPercent = 0;
    public float EnemyAngerBarPercent => curEnemyAnger / maxEnemyAnger;
    public int StarCount
    {
        get
        {
            if (GameOverPercent < 0.33f) return 3;
            else if (GameOverPercent < 0.66f) return 2;
            else return 1;
        }
    }

    public void OverDistanceLimit(bool overLimit)
    {
        if (GameManager.Instance.IsGameOver) return;

        if (overLimit)
        {
            curEnemyAnger += Time.deltaTime * increaseSpeed;
            curEnemyAnger = Mathf.Min(curEnemyAnger, maxEnemyAnger);
        }
        else
        {
            curEnemyAnger -= Time.deltaTime * decreaseSpeed;
            curEnemyAnger = Mathf.Max(curEnemyAnger, 0);
        }
        if (curEnemyAnger >= maxEnemyAnger)
        {
            GameManager.Instance.AngerFull();
        }
        else
        {
            GameOverPercent = MathF.Max(GameOverPercent, EnemyAngerBarPercent);
        }            
    }    
}
